<?php
	// Entête
	$pdf=new FPDF;
	$pdf->setTitle('Saisie des salles', true);
	$pdf->AddPage();
	$pdf->SetFont('Arial','B',20);
	$pdf->Cell(0,10,utf8_decode('Salles à compléter'));
     $pdf->Ln(18);

	foreach ( $promotions AS $promotion ):
		if ( empty($promotion->seances) ) continue;
		$pdf->SetFont('Arial','B',15);
		$pdf->Cell(0,0,utf8_decode($promotion->titre));
		$pdf->Ln(6);

		// Tableau
		//
		//Couleurs, épaisseur du trait et police grasse
		$pdf->SetFillColor(200);
		$pdf->SetTextColor(0);
		$pdf->SetDrawColor(100);
		$pdf->SetLineWidth(.1);
		$pdf->SetFont('','',10);

		//En-tête
	    $w = array(75,30,30,55);
	    $header = array(utf8_decode('UE'), utf8_decode('Date'), utf8_decode('Horaires'), utf8_decode('Salle'));
	    for($i=0;$i<count($header);$i++)
		   $pdf->Cell($w[$i],8,$header[$i],1,0,'C',1);
	    $pdf->Ln();

		//Restauration des couleurs et de la police
		$pdf->SetFillColor(240);
		$pdf->SetTextColor(0);
		$pdf->SetFont('');

		$fill=false;
		foreach($promotion->seances AS $seance):
			$pdf->Cell($w[0],6,utf8_decode($seance->type_enseignement . ' ' . apostrophe('de', $seance->ue)),'LR',0,'L',$fill);
			$pdf->Cell($w[1],6,utf8_decode(Date::fromSGBD($seance->jour)->format('j F Y')),'LR',0,'L',$fill);
			$pdf->Cell($w[2],6,utf8_decode(DateTime::createFromFormat('H:i:s',$seance->heure_debut)->format('H\hi') . ' - ' . DateTime::createFromFormat('H:i:s',$seance->heure_fin)->format('H\hi')),'LR',0,'L',$fill);
			$pdf->Cell($w[3],6,'','LR',0,'L',$fill);
			$pdf->Ln();
		
			$fill = !$fill;
		endforeach;
		 $pdf->Cell(array_sum($w),0,'','T');
		$pdf->Ln(15);
	endforeach;


	// Sortie
	$pdf->Output('saisie-des-salles-'.Date::today()->toURL().'.pdf','I');

?>